Learn DDL Commands of SQL & Its types

您所在的位置:网站首页 create type as table Learn DDL Commands of SQL & Its types

Learn DDL Commands of SQL & Its types

2023-04-14 13:39| 来源: 网络整理| 查看: 265

Table of Contents

Introduction

To access data stored in a relational database, use SQL, DDL Commands. Large volumes of data can be extracted quickly and effectively with SQL. Due to its compatibility with various database systems like Oracle, IBM, Microsoft, etc., SQL is versatile. You can manage databases with SQL without having a lot of coding knowledge

What is SQL?

As we are all aware, the database language used to conduct specific operations on an existing database is called Structured Query Language (SQL). Additionally, we can build a database using this language. To complete the necessary operations, SQL employs particular commands like Create, Drop, Insert, etc.

What is SQL Used For?

What is SQL Used For

The major purpose of this database language is to keep the data in relational database management systems. Data professionals use it as a specialized tool to manage structured data.

It is also intended for use with RDBMS stream processing. The database can be readily created and modified, and table rows and columns can be accessed and changed, among other things. It serves as a means of accessing and interacting with data in relational database management systems like MySql, MS SQL Server, Oracle Sybase, and others.

What are SQL Commands?

The instructions needed to interface with a database in order to carry out operations, functions, and queries on data are known as SQL commands. The database can be searched using SQL commands, and they can also be used to create, add data to, change, and drop tables, among other things.

Types of SQL Commands

Types of SQL Commands

These SQL commands are primarily divided into the following five categories:

DDL – Data Definition LanguageDQL – Data Query LanguageDML – Data Manipulation LanguageDCL – Data Control Language TCL – Transaction Control LanguageDDL (Data Definition Language): 

The SQL statements that can be used to specify the database schema make up DDL Commands, or Data Definition Language. It is used to create and modify the structure of database objects in the database and only works with descriptions of the database schema. Although data cannot be created, altered, or deleted with DDL Commands, database structures can. Typically, a typical user won’t use these commands; instead, they should use an application to access the database.

List of DDL commands: 

CREATE: The database or its objects are created with this command.DROP: Using this command, objects can be removed from the database.ALTER: This is done to change the database’s organizational structure.TRUNCATE: This is used to remove every record from a table, along with any spaces set aside for the records.COMMENT: With this, comments can be added to the data dictionary..RENAME: This is used to rename an existing database object.DQL (Data Query Language)

DQL (Data Query Language)

DQL statements are employed to conduct inquiries on the information contained in schema objects. The DQL Command’s objective is to obtain a schema relation based on the query that is supplied to it. DQL can be explained as follows: It’s a part of a SQL statement that enables retrieving data from a database and applying order to it. DDL Commands, The SELECT statement is present. With the help of this command, you can retrieve data from the database and manipulate it. A front-end program receives or may display the results of a SELECT query against a table or tables after they have been assembled into another temporary table.

List of DQL: 

SELECT: It is utilised to get information out of the database.DML(Data Manipulation Language)

The majority of SQL statements are part of the DML, or Data Manipulation Language, which also includes the SQL instructions that deal with manipulating the data that is already existing in the database. It is the part of the SQL statement in charge of managing database and data access. DDL Commands, Basically, DML statements and DCL statements belong together.

List of DML commands: 

INSERT : It is used to insert data into a table.UPDATE: It is used to update existing data within a table.DELETE : It is used to delete records from a database table.LOCK: Table control concurrency.DCL (Data Control Language): 

GRANT and REVOKE are two commands in DCL that are primarily concerned with the rights, permissions, and other controls of the database system. 

List of  DCL commands: 

GRANT: This command gives users access privileges to the database.REVOKE: This command withdraws the user’s access privileges given by using the GRANT commandTCL (Transaction Control Language)

A group of tasks are combined into a single execution unit using transactions. SQL Database Dates, Each transaction starts with a particular task and is completed once every activity in the group has been properly completed. The transaction fails if any of the tasks are unsuccessful. DDL Commands,  Therefore, there are only two outcomes for a transaction: success or failure. You can explore more about transactions here. Consequently, the execution of a transaction is controlled by the following TCL instructions.: 

BEGIN: Opens a Transaction.COMMIT: Commits a Transaction.ROLLBACK: Rollbacks a transaction in case of any error occurs.SAVEPOINT: Sets a save point within a transaction.SET TRANSACTION: Specifies characteristics for the transactionHere we discuss about DDL Commands

Here we discuss about DDL Commands

DDL Commands

A component of DBMS, Data Definition Language (DDL) is a subset of SQL.(Database Management System). DDL Commands, Commands like CREATE, ALTER, TRUNCATE, and DROP are all part of DDL. The SQL tables can be created or modified using these instructions.

Have a look at: best data science institute in India

We will discuss the following DDL commands in this section.CreateAlter truncatedropRename CREATE :In DDL Commands in SQL, a new table can be created using this command. Information like the table name, column names, and datatypes must be provided by the user.Syntax –

CREATE TABLE table_name

(

column_1 datatype,

column_2 datatype,

column_3 datatype,

….

);

Example –For the purpose of storing student data from a specific college, a table needs to be created. DDL Commands, Create syntax would look like this.

CREATE TABLE Student_info

(

College_Id number(2),

College_name varchar(30),

Branch varchar(10)

);

ALTER :

The existing table’s columns can be changed, deleted, or added with this command in DDL Commands. The user can quickly add, delete, or change tasks; however, they require knowledge of the name of the current table.

Syntax –Syntax to add a column to an existing table.

ALTER TABLE table_name

ADD column_name datatype;

Example –We would like to add a new column for CGPA to our Student_info table. The sentence structure would be as follows:.

ALTER TABLE Student_info

ADD CGPA number;

TRUNCATE :

Although all of the rows in the table are removed with this command in DDL Commands, the table’s structure remains.

Syntax –Syntax to remove an existing table.

TRUNCATE TABLE table_name;

Example –The College Authority wants to preserve the table structure but wants to erase all student information for fresh batches. They may issue the following command.

TRUNCATE TABLE Student_info

DROP:

This command is used to delete an existing table from the database together with its structure.

Syntax –Syntax to drop an existing table.

DROP TABLE table_name;

Example –Delete the Student_info Table if the College Authority wants to make changes to its database. 

DROP TABLE Student_info;

RENAME:

Using the simple RENAME command, a table’s name can be changed with or without data present.

Any table object may be renamed at any moment.

Syntax –

RENAME TABLE To ;

Example:

We can use the rename command as follows to alter the table’s name from Employee to Emp.

RENAME TABLE Employee To EMP;

Also read: data science course fees in Mumbai

Conclusion

The DDL commands in SQL are used to specify the kind and structure of the data that will be stored in a database and to establish database schema. DDL Commands is used for establishing new tables, indexes, sequences, stogroups, etc. and for defining the features of these objects, such as data type, field length, and alternative table names. DDL Commands deals with descriptions of the database schema. (aliases).



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3